

#pragma once 

#include <string>
#include <ostream>

#include "topdbs_base_session.hpp"
#include "sqlite3_connection.hpp"

struct sqlite3;
struct sqlite3_stmt;

namespace topdbs
{
	class sqlite3_session 
		: public topdbs_base_session
	{	
	protected:
		sqlite3_connection* m_pConnection;	
		sqlite3_stmt* m_pStmt;
	public:	
		sqlite3_session();
		sqlite3_session(sqlite3_connection* pConnection);
		virtual ~sqlite3_session();

		int PutDataToRow(string& k,string& v);
		int PutDataToRes(stringmap_row_t& row);		

		//! reset the current command all info.
		virtual void Reset() override;
		//! Validates and prepares the current command for execution.
		virtual int  Prepare() override;
		//! Executes the current command.
		virtual int  Execute() override; 
		virtual int  Execute(const char* sSQL,...) override; 	
		virtual int  ExecuteV(const string& sSQL,va_list vaList) override;
		virtual int  ExecuteFetch(const string& sSQL) override;
		virtual bool FetchNext() override;
		virtual bool FetchCursorNext(uint16_t nFetchSize = TOPDBS_DEFAULT_FETCH_SIZE) override;
		//! Binding the command parameter specified by its position. 
		//! The second argument is the index of the SQL parameter to be set.
		//! The leftmost SQL parameter has an index of 1. 
		virtual int  BindParams(const uint16_t paramno,const DBSValue& value) override;
		virtual int  BindParams(const uint16_t paramno,const string& value)   override;
		virtual int  BindParams(const uint16_t paramno,const int     value)   override;
		virtual int  BindParams(const uint16_t paramno,const long    value)   override;
		virtual int  BindParams(const uint16_t paramno,const float   value)   override;
		virtual int  BindParams(const uint16_t paramno,const double  value)   override;
	private:
		int ExecuteUpdate(const std::string& sSQL);
		int ExecuteQuery(const std::string& sSQL);
		int ExecuteQuery_Row(const std::string& sSQL);
	};
}
